# coding: utf-8

from me.api_utils import *
from me.api_utils import WXAppAPIView as APIView
from me.netease_music import search_music
from api_wxapp.model_serializers import *


class MusicSearchAPIView(APIView):

    def post(self, request):
        key = request.data.get('key', '')
        equal_and_exception(key, '', 3000)
        res = search_music(key)
        return success_resp(res)


class MusicListAPIView(APIView):

    def get(self, request):
        res = MusicGroup.objects.all().prefetch_related('music_set')
        return success_resp(MusicGroupSerializer(instance=res, many=True).data)